package com.yljk.homedoctor.view.ui;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.bumptech.glide.Glide;
import com.yilijk.base.utils.ALog;
import com.yljk.homedoctor.R;
import com.yljk.homedoctor.model.entity.VideoEntity;

import cn.jzvd.MyJzvdStd;

import com.yljk.servicemanager.constants.RouterApi;
import com.yljk.servicemanager.oldbase.ModuleBaseActivity;

import cn.jzvd.Jzvd;

@Route(path = RouterApi.VideoInfoActivity)
public class VideoInfoActivity extends ModuleBaseActivity {

    private MyJzvdStd videoPlayer;
    private ImageView backIv;
    private TextView hospitalname, doctorname, departmentname, title;
    private ImageView headImg;

    public VideoEntity videoEntity;

    @Override
    public int bondLayout() {
        return R.layout.activity_video;
    }

    @Override
    public void initView() {
        videoPlayer = findViewById(R.id.video_player);
        backIv = findViewById(R.id.back_iv);
        hospitalname = findViewById(R.id.hospitalname);
        doctorname = findViewById(R.id.doctorname);
        departmentname = findViewById(R.id.departmentname);
        title = findViewById(R.id.videotitle);
        headImg = findViewById(R.id.headImg);

        videoEntity = (VideoEntity) getIntent().getSerializableExtra("videoEntity");

        if (videoEntity != null) {
            hospitalname.setText(videoEntity.getHospitalName());
            doctorname.setText(videoEntity.getDoctorName());
            departmentname.setText(videoEntity.getDoctorJobTitle() + "  " + videoEntity.getDoctorDepartmentName());
            title.setText(videoEntity.getTitle());
            Glide.with(this).load(videoEntity.getDoctorAvatar()).into(headImg);
            String url = videoEntity.getFrequencyUrl();
            if (url.substring(0,5).equals("https")){
                url = "http"+url.substring(5,url.length());
            }
            videoPlayer.setUp(url,"");
            ALog.e("videoActivity", url);
            videoPlayer.startVideo();
        }
    }

    @Override
    public void initData() {
    }

    @Override
    public void initEvent() {
        backIv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Jzvd.releaseAllVideos();
                if (Jzvd.backPress()) {
                    return;
                }
                finish();
            }
        });
    }


    @Override
    protected void onPause() {
        super.onPause();
        Jzvd.releaseAllVideos();
    }

    @Override
    public void onBackPressed() {
        if (Jzvd.backPress()) {
            return;
        }
        super.onBackPressed();
    }


}
